package org.insia.smartposse.manager.list;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.insia.smartposse.manager.FreelanceBookManager;
import org.insia.smartposse.manager.UserManager;
import org.insia.smartposse.mapping.FreelanceBooks;
import org.insia.smartposse.mapping.dao.FreelanceBooksDAO;

public class FreelanceBooksListManager extends ArrayList {

	private List<FreelanceBooks> _books = new ArrayList<FreelanceBooks>();
	private final FreelanceBooksDAO _dao = new FreelanceBooksDAO();
	private final Session _session;
	
	public FreelanceBooksListManager() {
		_session = _dao.getSession();
	}

	public List<FreelanceBooks> findByFreelance(UserManager user) {
		return _dao.findBooksByFreelance(user.getUser(), _session);
	}
	
	@Override
	public FreelanceBookManager get(int index) {
		return new FreelanceBookManager(_books.get(index));
	}

	@Override
	public int size() {
		return _books.size();
	}
}
